package com.yanqu.road.server.cmd.activity.washe.cross;

import com.yanqu.road.entity.activity.washe.data.WasheTmpBadgeResult;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.WashePb;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_WASHE_SEE_OTHER_USER_DATA_FROM_CROSS, desc = "")
public class WasheSeeOtherUserDataFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        WasheProto.ChannelWasheSeeOtherUserDataReqMsg reqMsg = WasheProto.ChannelWasheSeeOtherUserDataReqMsg.parseFrom(yanQuMessage.getBytes());

        ServerInfo serverInfo = ServerListMgr.getServerInfo(GameServer.getInstance().getServerId());

        WasheTmpBadgeResult result = WasheMgr.getCacheWasheTmpBadgeResult(reqMsg.getSeeUserId());
        WasheProto.WasheSeeOtherUserDataRespMsg.Builder builder = WasheProto.WasheSeeOtherUserDataRespMsg.newBuilder();
        builder.setRet(0);
        builder.setServerName(serverInfo.getServerName());

        builder.setOtherChannel(true); // builder.setOtherChannel(serverInfo.getChannelId() != reqMsg.getFromChannelId());

        builder.setCur(WashePb.parseWasheBadgeMsg(result.getCur()));
        builder.setTop(WashePb.parseWasheBadgeMsg(result.getTop()));

        WasheProto.ChannelWasheSeeOtherUserDataRespMsg.Builder resp = WasheProto.ChannelWasheSeeOtherUserDataRespMsg.newBuilder();
        resp.setFromChannelId(reqMsg.getFromChannelId());
        resp.setFromServerId(reqMsg.getFromServerId());
        resp.setFromUserId(reqMsg.getFromUserId());
        resp.setResp(builder);

        YanQuMessage message = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_WASHE_SEE_OTHER_USER_DATA_RESP, resp);
        GamePlayerMgr.sendPacket(0, message);
    }
}
